* Firm organization with multiple establishments
* Section III.B: Appendix Tables B.2-B.3

clear all 
set matsize 4000
set more off

capture log close
log using log/10_facts-cs_MEorg_layer-est.log, replace

use data/MEorg_2012_cs_layer-est.dta, clear
count

********************************************************************************
***	Establishment/HQ-level analyses	********************************************
********************************************************************************

gen shr_mgmt_w_bet_glm = shr_mgmt_w_bet / 100
sum shr_mgmt_w_bet_glm
label variable shr_mgmt_w_bet_glm "Managerial share in wage sum, layer"

gen shr_bloss_w_bet_glm = shr_bloss_w_bet / 100
sum shr_bloss_w_bet_glm
label variable shr_bloss_w_bet_glm "Managerial share in wage sum, Blossfeld"

//	# FE: 256 (HQ: 244) wz 2008, 207 (201) wz 1993, 402 ao_kreis
global FEestHQ		"d_est_08wz* d_ao_kreis*" 
global FEestHQ93	"d_est_93wz* d_ao_kreis*" 
global optSEest		"vce(cluster untid)"
global optSEHQ		"vce(robust)"
global optGLM		"link(logit) family(binomial) nolog"
global opttab		"b(%9.3f) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) compress mtitles style(tex) label"

********************************************************************************
***	Descriptives ***************************************************************

*	# layers HQ vs. establishments
qui gen aux = count_mgmt_bet if hauptbet == 1
bys untid: egen count_mgmt_haupt = min(aux)
drop aux

//	Share of establishments with more/same/fewer layers than headquarters
tab2 count_mgmt_bet count_mgmt_haupt if hauptbet == 0

********************************************************************************
***	Table B.3: Mg. organization of establishments and headquarters

eststo col1, title("\# layers"): qui poisson count_mgmt_bet ln_prdt_workers ldistall 	$FEestHQ if hauptbet == 0, $optSEest
eststo col2, title("Mg.share"):  qui glm shr_mgmt_w_bet_glm ldistall 					$FEestHQ if hauptbet == 0, $optGLM $optSEest
eststo col3, title("Mg.share"):  qui glm shr_bloss_w_bet_glm ldistall 					$FEestHQ if hauptbet == 0, $optGLM $optSEest

eststo col4, title("\# layers"): qui poisson count_mgmt_bet ln_prdt_workers max_log_dist	$FEestHQ if hauptbet == 1, $optSEHQ
eststo col5, title("Mg.share"):  qui glm shr_mgmt_w_bet_glm max_log_dist 					$FEestHQ if hauptbet == 1, $optGLM $optSEHQ
eststo col6, title("Mg.share"):  qui glm shr_bloss_w_bet_glm max_log_dist  					$FEestHQ if hauptbet == 1, $optGLM $optSEHQ

esttab col1 col2 col3 col4 col5 col6, ///
	$opttab se(%9.3f) indicate($FEestHQ, labels(Y N)) order(ldistall max_log_dist ln_prdt_workers) 
esttab col1 col2 col3 col4 col5 col6, ///
	$opttab p(%9.3f)  indicate($FEestHQ, labels(Y N)) order(ldistall max_log_dist ln_prdt_workers) 

********************************************************************************
***	Firm-level analyses	********************************************************
********************************************************************************

estimates clear

keep if flg_untjhr == 1
drop flg_untjhr
drop d_ao_kreis* d_est_08wz* d_est_93wz*

drop betnr w93_3_gen w08_3 ao_kreis hauptbet empl_bet distance* ldist* ///
	count_mgmt_bet shr_mgmt_bet prdt_wkrs_bet ln_prdt_workers shr_mgmt_w_bet shr_mgmt_bet_bloss ///
	shr_bloss_w_bet* wage_bet_bloss 

cap drop shr_mgmt_w_unt_glm
gen shr_mgmt_w_unt_glm = shr_mgmt_w_unt / 100
sum shr_mgmt_w_unt_glm
label variable shr_mgmt_w_unt_glm "Managerial share in wage sum, layer"

cap drop shr_bloss_w_unt_glm
gen shr_bloss_w_unt_glm = shr_bloss_w_unt / 100
sum shr_bloss_w_unt_glm
label variable shr_bloss_w_unt_glm "Managerial share in wage sum, Blossfeld"

global FEunt	"d_08wz* d_hq_kreis* d_legal*" // d_08wz bezieht sich auf HQ Sektor
global FEunt93	"d_93wz* d_hq_kreis* d_legal*" // d_93wz bezieht sich auf HQ Sektor
global optSEunt	"vce(robust)"

********************************************************************************
***	Table B.2: Mg. organization of firm ******************************************

eststo col1, title("\# layers"): qui poisson count_mgmt_unt ln_sales max_log_dist	$FEunt, $optSEunt
eststo col2, title("\# layers"): qui poisson count_mgmt_unt ln_sales ln_area  		$FEunt, $optSEunt
eststo col3, title("\# layers"): qui poisson count_mgmt_unt ln_prdt_wkr_unt max_log_dist	$FEunt, $optSEunt
eststo col4, title("\# layers"): qui poisson count_mgmt_unt ln_prdt_wkr_unt ln_area			$FEunt, $optSEunt

eststo col5, title("Mg.share"): qui glm shr_mgmt_w_unt_glm max_log_dist 	$FEunt, $optGLM $optSEunt
eststo col6, title("Mg.share"): qui glm shr_mgmt_w_unt_glm ln_area  		$FEunt, $optGLM $optSEunt
eststo col7, title("Mg.share"): qui glm shr_bloss_w_unt_glm max_log_dist	$FEunt, $optGLM $optSEunt
eststo col8, title("Mg.share"): qui glm shr_bloss_w_unt_glm ln_area			$FEunt, $optGLM $optSEunt

esttab col1 col2 col3 col4 col5 col6 col7 col8, ///
	$opttab se(%9.3f) indicate($FEunt, labels(Y N)) order(max_log_dist ln_area ln_sales ln_prdt_wkr_unt)
esttab col1 col2 col3 col4 col5 col6 col7 col8, ///
	$opttab p(%9.3f)  indicate($FEunt, labels(Y N)) order(max_log_dist ln_area ln_sales ln_prdt_wkr_unt)

log close
